Sentry Integration
Catalyst-core provides a built-in SDK for Sentry integration, making it easy to monitor errors and performance in your application. The SDK simplifies the setup process and provides a unified interface for both client and server-side error tracking.
Installation
First, install the required Sentry packages for your application:
npm install @sentry/react @sentry/node
Basic Setup
Import the Sentry object from catalyst-core:
import Sentry from "catalyst-core/sentry";
Configuration
Sentry Configuration File
Create a sentry.config.json
file at the same level as your config.json
file:
{
"dsn": "YOUR_SENTRY_DSN",
"clientOptions": {
"environment": "development",
"tracesSampleRate": 1.0,
"replaysSessionSampleRate": 0.1,
"replaysOnErrorSampleRate": 1.0
},
"serverOptions": {
"environment": "development",
"tracesSampleRate": 1.0,
"profilesSampleRate": 1.0
},
"enableTracing": true,
"enableProfiling": true,
"release": "1.0.0"
}
Initialization
Client-side Initialization
Initialize Sentry on the client side in your client.js
file:
// client.js
import { Sentry } from "catalyst-core/sentry";
Sentry.init({
dsn: "YOUR_SENTRY_DSN",
environment: process.env.NODE_ENV,
tracesSampleRate: 1.0,
});
Server-side Initialization
Initialize Sentry on the server side using the preServerInit
lifecycle method:
// In your server configuration
import { Sentry } from "catalyst-core/sentry";
export const preServerInit = () => {
Sentry.init({
dsn: "YOUR_SENTRY_DSN",
environment: process.env.NODE_ENV,
tracesSampleRate: 1.0,
});
};
Available Functions
The catalyst-core Sentry SDK exports several utility functions for error tracking and monitoring:
captureException
Capture and report exceptions to Sentry:
import { Sentry } from "catalyst-core/sentry";
try {
// Some code that might throw an error
throw new Error("Something went wrong!");
} catch (error) {
Sentry.captureException(error);
}
captureMessage
Send custom messages to Sentry:
import { Sentry } from "catalyst-core/sentry";
Sentry.captureMessage("User performed a critical action", "info");
addBreadcrumb
Add breadcrumbs to track the sequence of events leading up to an error:
import { Sentry } from "catalyst-core/sentry";
Sentry.addBreadcrumb({
message: "User clicked on submit button",
level: "info",
category: "ui.interaction",
});